<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script !src="">
    //方式1，写在对象内部
    let zsh = {
        name:'zsh',
        birth:'2001',
        //方法
        age:function () {
            let now = new Date().getFullYear();
            return now - this.birth;
        }
    }

    console.log(zsh.age());

    //方法2，写在外部，赋值给方法
    function getAge() {
        let now = new Date().getFullYear();
        console.log(this.birth);
        return now - this.birth;
    }

    let zsh2 = {
        ame:'zsh',
        birth:'2001',
        //方法
        age:getAge()
    }

    //apply 显示指示调用的对象，使得this可用
    getAge.apply(zsh2,[]);


</script>
</body>
</html>